﻿using UnityEngine;
namespace UGUIMan
{
    public class eyeclip:MonoBehaviour
    {
        public Vector3 delta;
        public Vector3 pos;
        public Animator animator;
        public GameObject eye;
        public int clipcount=0;
        Vector3 playdelta;
        private void Awake()
        {
            eye = GameObject.Find("Eye0");
            animator = GetComponent<Animator>();
            playdelta = delta;
        }
        private void Start()
        {
            InvokeRepeating("cflag", 10, 10);
        }
        private void Rotate()
        {

        }

        public void PlayIdle()
        {
            animator.Play(this.name, clipcount);
        }

        public void PlayClose()
        {
            animator.rootPosition = eye.transform.position;
            animator.playbackTime = 2;
            animator.StartPlayback();
        }

        void CloseMove()
        {

        }

        void cflag()
        {
            m_closeflag = !m_closeflag;
        }

        public void Stop()
        {
            clipcount = animator.layerCount;
        }
        public static bool closeflag
        {
            get
            {
                return GameObject.Find("Eyecliptop").GetComponent<eyeclip>().m_closeflag&& GameObject.Find("Eyecliptop").GetComponent<eyeclip>().m_closeflag;
            }
        }
        public bool m_closeflag;
        private void Update()
        {
            pos = GameObject.Find("Eye0").transform.localPosition;
            transform.localPosition = pos + playdelta;
            if (closeflag)
            {
                PlayClose();
                m_closeflag = false;
            }
        }
    }
}